Summary

Using various spatial data wrangling and visualization methods, we will explore the California oil spill incidents gathered by the The Office of Spill Prevention and Response (OSPR) Incident Tracking Database. We will further isolate spills by county in 2008. For the purposes of this database, “incidents” are “discharges or threatened discharges of petroleum or other deleterious material into the waters of the state.”

Source: Oil Spill Incident Tracking [ds394], 2009-07-23

# Read in California county shapefile 
# Shapefile will act as the polygon needed for visualization/population of data 
# Data wrangle to manipulate data easily, isolate two attributes using select() and rename() for better recall 

ca_counties <- read_sf(here("data", "ca_counties", "CA_Counties_TIGER2016.shp")) %>% 
  select(NAME, ALAND) %>% 
  rename(county_name = NAME, land_area = ALAND)
# Read in CA DFW Oil Spill dataset ds394
oil_spill <- read_sf(here("data", "Oil_Spill_Incident_Tracking_%5Bds394%5D-shp")) %>% 
  filter(INLANDMARI == "Inland")

Exploratory interactive map

# Use {tmap} to make an interactive map 
tmap_mode(mode = "view")
## tmap mode set to interactive viewing
tm_shape(ca_counties) +
  tm_fill("land_area") + 
  tm_shape(oil_spill) + 
  tm_dots()

Finalized chloropleth map

# Use st_join() to join the datasets to obtain counts by county 
ca_oil_spill <- ca_counties %>% 
  st_join(oil_spill)

# Use counts() to find counts of incidents by county 
ca_oil_spill_counts <- ca_oil_spill %>% 
  count(county_name)
# Plot a chloropleth using the number of oil spill incidents as the fill color 

ggplot(data = ca_oil_spill_counts) + 
  geom_sf(aes(fill = n), color = "white", size = 0.1) + 
  scale_fill_gradientn(colors = c("lightgray", "orange", "red")) + 
  theme_bw() + 
  labs(title = "CA inland oil spill incidents by county (2008)",
       fill = "Number of oil spills")